package cn.example.vip.mall.seckill.controller;

import cn.example.vip.mall.seckill.entity.SeckillGoods;
import cn.example.vip.mall.seckill.service.SeckillGoodsService;
import cn.example.vip.mall.util.RespResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping(value = "/seckill/goods")
public class SeckillGoodsController {

    @Autowired
    private SeckillGoodsService seckillGoodsService;
    
    /**
     * 根据 Seckill Id 查询秒杀商品详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public RespResult<SeckillGoods> queryBySeckillId(@PathVariable("id") String id) {
        SeckillGoods seckillGoods = seckillGoodsService.getById(id);
        return RespResult.ok(seckillGoods);
    }
    
    /**
     * 根据活动id 查询商品
     * @param id
     * @return
     */
    @GetMapping("/act/{id}")
    public RespResult<List<SeckillGoods>> queryByActId(@PathVariable("id") String id) {
        List<SeckillGoods> seckillGoods = seckillGoodsService.activityGoods(id);
        return RespResult.ok(seckillGoods);
    }
}
